package top.laoshuzi.designpatterns.base.behavior.command;

import org.junit.Test;

public class Client {

    @Test
    public void operation() {

        //初始化
        Receiver receiver = new Receiver();
        Command command1 = new ConcreteCommand1(receiver);
        Command command2 = new ConcreteCommand2(receiver);
        Command command3 = new ConcreteCommand3(receiver);
        MacroCommand macroCommand = new ConcreteMacroCommand();
        macroCommand.add(command3);
        macroCommand.add(command2);
        macroCommand.add(command1);

        //设置命令
        Invoker invoker = new Invoker();
        invoker.setCommand1(command1);
        invoker.setCommand2(command2);
        invoker.setCommand3(command3);
        invoker.setCommand4(macroCommand);

        //执行
        invoker.action1();
        invoker.action2();
        invoker.action3();
        invoker.action4();
    }
}
